/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DataAccess;

import Adapter.DomainAdapter;
import be.ac.ulg.montefiore.run.jahmm.*;
import java.io.FileReader;
import java.io.File;
import java.io.BufferedReader;
import java.util.ArrayList;
import Domain.*;
import java.util.List;
import java.io.IOException;

/**
 *
 * @author Allen
 */

/**/
public class HmmReader {
    static List<Hmm<ObservationDiscrete<Output>>> readHmms(String filename){
        File file = new File(filename);
        BufferedReader reader = null;
        List<Hmm<ObservationDiscrete<Output>>> hmm_list =
                new ArrayList<Hmm<ObservationDiscrete<Output>>>();
        HmmParser hp = new HmmParser();

        int line = 0;
         try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            String tempString2 = null;
            while ((tempString = reader.readLine()) != null
                    && (tempString2 = reader.readLine()) != null) {
                String str = tempString.concat(tempString2);
                double [][] T = new double[3][3];
                double [][] O = new double[3][3];
                hp.parse(str, T, O);
                hmm_list.add(DomainAdapter.toHmm(T, O));
                line ++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
            return hmm_list;
        }
    }
}


